#!/usr/bin/env bash
# Copyright (c) 2021 maminjie <maminjie2@huawei.com>
# SPDX-License-Identifier: MulanPSL-2.0

method_def createyaml

usage_createyaml() {
    echo "createyaml (cyaml): Create a local yaml file of repo"
    echo ""
    echo "usage:"
    echo "    ${PROG} cyaml FILE.yaml"
    echo "    ${PROG} cyaml              # create a yaml file named by the current directory"
    echo ""
}

alias_def createyaml cyaml
# do_createyaml FILE.yaml
# do_createyaml
do_createyaml() {
    local yamlfile=""
    if [ $# -eq 1 ]; then
        yamlfile=$1
    elif [ $# -eq 0 ]; then
        yamlfile=$(basename $(pwd)).yaml
    else
        usage_createyaml; exit
    fi

    if [ -z "$yamlfile" ]; then
        usage_createyaml; exit
    fi

# Leave a space behind each field
printf "\
version_control: \n\
src_repo: \n\
tag_prefix: \"^v\"
separator: \".\"
" > $yamlfile

    vim $yamlfile
}
